package com.houweishi.module.addressBook.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.addressBook.domain.AddressBook;
import com.houweishi.module.addressBook.service.IAddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通讯录页面Controller
 * 
 * @author yqq
 * @date 2023-06-27
 */
@RestController
@RequestMapping("/module/addressBook")
public class AddressBookController extends BaseController
{
    @Autowired
    private IAddressBookService addressBookService;

    /**
     * 查询通讯录页面列表
     */
    @PreAuthorize("@ss.hasPermi('module:addressBook:list')")
    @GetMapping("/list")
    public TableDataInfo list(AddressBook addressBook)
    {
        startPage();
        List<AddressBook> list = addressBookService.selectAddressBookList(addressBook);
        return getDataTable(list);
    }

    /**
     * 导出通讯录页面列表
     */
    @PreAuthorize("@ss.hasPermi('module:addressBook:export')")
    @Log(title = "通讯录页面", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AddressBook addressBook)
    {
        List<AddressBook> list = addressBookService.selectAddressBookList(addressBook);
        ExcelUtil<AddressBook> util = new ExcelUtil<AddressBook>(AddressBook.class);
        util.exportExcel(response, list, "通讯录页面数据");
    }

    /**
     * 获取通讯录页面详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:addressBook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(addressBookService.selectAddressBookById(id));
    }

    /**
     * 新增通讯录页面
     */
    @PreAuthorize("@ss.hasPermi('module:addressBook:add')")
    @Log(title = "通讯录页面", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddressBook addressBook)
    {
        return toAjax(addressBookService.insertAddressBook(addressBook));
    }

    /**
     * 修改通讯录页面
     */
    @PreAuthorize("@ss.hasPermi('module:addressBook:edit')")
    @Log(title = "通讯录页面", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddressBook addressBook)
    {
        return toAjax(addressBookService.updateAddressBook(addressBook));
    }

    /**
     * 删除通讯录页面
     */
    @PreAuthorize("@ss.hasPermi('module:addressBook:remove')")
    @Log(title = "通讯录页面", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(addressBookService.deleteAddressBookByIds(ids));
    }
}
